package com.hz.web.controller.front;

import com.hz.web.entity.*;
import com.hz.web.entity.vo.*;
import com.hz.web.service.*;
import com.hz.web.util.DateUtil;
import com.hz.web.util.IdCreator;
import org.jsoup.helper.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.*;


/**
 * ckType
 * 协会介绍  50
 * 资质评定  26
 * 信用评价  27
 * 人员认定  30
 * 标准规范  31
 * <p>
 * 新闻热点（协会要闻） 8
 * 通知      9
 * 技术动态 10
 * 通知公告  11
 * 政策法规  12
 * 展会信息  13
 * 安防产品 21
 * 行业动态 22
 * 协会章程 23
 */


@Controller
@RequestMapping("front")
public class IndexController extends BasicController {

    @Resource
    private IlinkService linkService;
    @Resource
    private IckHtmlService ckHtmlService;
    @Resource
    private ICompanyBaseService companyBaseService;
    @Resource
    private IuserService userService;
    @Resource
    private ICertificatoryCampanyService certificatoryCampanyService;
    @Resource
    private ICertificatoryPerService certificatoryPerService;
    @Resource
    private IemployeeService employeeService;


    /**
     * 首页相关的文章信息
     *
     * @param session
     * @return
     */
    @RequestMapping("index")
    @ResponseBody
    public IndexResponseVo index(HttpSession session) {

        IndexResponseVo indexResponseVo = new IndexResponseVo();
        LinkedHashMap<String, List<IndexNewsVo>> result = new LinkedHashMap<>();

        // 新闻热点
        List<IndexNewsVo> newsList = new ArrayList<>();

        Map<String, Object> parmsMapForNews = new HashMap<String, Object>();// 参数map
        parmsMapForNews.put("ckType", 8);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForNews.put("state", "1");
        //parmsMapForNews.put("imgpd", "a"); // 不为空即可
        parmsMapForNews.put("sort", "yes");
        parmsMapForNews.put("index", 0);
        parmsMapForNews.put("end", 6);
        List<CkHtmlEntity> ckHtmlEntityListForNews = ckHtmlService.queryCkHtml(parmsMapForNews);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForNews) {
            String context = ckHtmlEntity.getHtml().substring(0, 200).replaceAll("</?[^>]+>", "").replaceAll("<a>\\s*|t|r|n</a>", "").replaceAll("&nbsp;", "");
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setIntro(context.length() > 30 ? context.substring(0, 30) : context);
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=18&ckType=8&id=" + ckHtmlEntity.getId());
            newsVo.setCreatedate(DateUtil.dateToStr(ckHtmlEntity.getCreateTime(), "yy/MM/dd"));
            newsList.add(newsVo);
        }
        result.put("news", newsList);


        // 通知
        List<IndexNewsVo> noticeList = new ArrayList<>();

        Map<String, Object> parmsMapForNotice = new HashMap<String, Object>();// 参数map
        parmsMapForNotice.put("ckType", 9);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForNotice.put("state", "1");
        //parmsMapForNotice.put("imgpd", "a"); // 不为空即可
        parmsMapForNotice.put("sort", "yes");
        parmsMapForNotice.put("index", 0);
        parmsMapForNotice.put("end", 8);
        List<CkHtmlEntity> ckHtmlEntityListForNotice = ckHtmlService.queryCkHtml(parmsMapForNotice);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForNotice) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=22&ckType=9&id=" + ckHtmlEntity.getId());
            noticeList.add(newsVo);
        }
        result.put("notice", noticeList);


        // 技术动态
        List<IndexNewsVo> technologyList = new ArrayList<>();

        Map<String, Object> parmsMapForTechnology = new HashMap<String, Object>();// 参数map
        parmsMapForTechnology.put("ckType", 10);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForTechnology.put("state", "1");
        //parmsMapForTechnology.put("imgpd", "a"); // 不为空即可
        parmsMapForTechnology.put("sort", "yes");
        parmsMapForTechnology.put("index", 0);
        parmsMapForTechnology.put("end", 10);
        List<CkHtmlEntity> ckHtmlEntityListForTechnology = ckHtmlService.queryCkHtml(parmsMapForTechnology);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForTechnology) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=12&ckType=10&id=" + ckHtmlEntity.getId());
            technologyList.add(newsVo);
        }
        result.put("technology", technologyList);


        // 通知公告
        List<IndexNewsVo> announceList = new ArrayList<>();

        Map<String, Object> parmsMapForAnnounce = new HashMap<String, Object>();// 参数map
        parmsMapForAnnounce.put("ckType", 11);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForAnnounce.put("state", "1");
        //parmsMapForAnnounce.put("imgpd", "a"); // 不为空即可
        parmsMapForAnnounce.put("sort", "yes");
        parmsMapForAnnounce.put("index", 0);
        parmsMapForAnnounce.put("end", 10);
        List<CkHtmlEntity> ckHtmlEntityListForAnnounce = ckHtmlService.queryCkHtml(parmsMapForAnnounce);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForAnnounce) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=24&ckType=11&id=" + ckHtmlEntity.getId());
            announceList.add(newsVo);
        }
        result.put("announce", announceList);


        // 安防产品
        List<IndexNewsVo> productsList = new ArrayList<>();

        Map<String, Object> parmsMapForProducts = new HashMap<String, Object>();// 参数map
        parmsMapForProducts.put("ckType", 21);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForProducts.put("state", "1");
        //parmsMapForProducts.put("imgpd", "a"); // 不为空即可
        parmsMapForProducts.put("sort", "yes");
        parmsMapForProducts.put("index", 0);
        parmsMapForProducts.put("end", 8);
        List<CkHtmlEntity> ckHtmlEntityListForProducts = ckHtmlService.queryCkHtml(parmsMapForProducts);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForProducts) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=43&ckType=21&id=" + ckHtmlEntity.getId());
            productsList.add(newsVo);
        }
        result.put("products", productsList);


        // 政策法规
        List<IndexNewsVo> lawsList = new ArrayList<>();

        Map<String, Object> parmsMapForLaws = new HashMap<String, Object>();// 参数map
        parmsMapForLaws.put("ckType", 12);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForLaws.put("state", "1");
        //parmsMapForLaws.put("imgpd", "a"); // 不为空即可
        parmsMapForLaws.put("sort", "yes");
        parmsMapForLaws.put("index", 0);
        parmsMapForLaws.put("end", 7);
        List<CkHtmlEntity> ckHtmlEntityListForLaws = ckHtmlService.queryCkHtml(parmsMapForLaws);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForLaws) {
            String context = ckHtmlEntity.getHtml().substring(0, 200).replaceAll("</?[^>]+>", "").replaceAll("<a>\\s*|t|r|n</a>", "").replaceAll("&nbsp;", "");
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setIntro(context.length() > 30 ? context.substring(0, 30) : context);
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=25&ckType=12&id=" + ckHtmlEntity.getId());
            lawsList.add(newsVo);
        }
        result.put("laws", lawsList);


        // 展会信息
        List<IndexNewsVo> infoList = new ArrayList<>();

        Map<String, Object> parmsMapForInfo = new HashMap<String, Object>();// 参数map
        parmsMapForInfo.put("ckType", 13);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForInfo.put("state", "1");
        //parmsMapForInfo.put("imgpd", "a"); // 不为空即可
        parmsMapForInfo.put("sort", "yes");
        parmsMapForInfo.put("index", 0);
        parmsMapForInfo.put("end", 6);
        List<CkHtmlEntity> ckHtmlEntityListForInfo = ckHtmlService.queryCkHtml(parmsMapForInfo);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForInfo) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=26&ckType=13&id=" + ckHtmlEntity.getId());
            newsVo.setImgsrc(pic_host + "/images/uploadimg/" + ckHtmlEntity.getImg());
            infoList.add(newsVo);
        }
        result.put("info", infoList);


        // 协会章程
        List<IndexNewsVo> associationList = new ArrayList<>();

        Map<String, Object> parmsMapForAssociation = new HashMap<String, Object>();// 参数map
        parmsMapForAssociation.put("ckType", 23);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForAssociation.put("state", "1");
        //parmsMapForAssociation.put("imgpd", "a"); // 不为空即可
        parmsMapForAssociation.put("sort", "yes");
        parmsMapForAssociation.put("index", 0);
        parmsMapForAssociation.put("end", 1);
        List<CkHtmlEntity> ckHtmlEntityListForAssociation = ckHtmlService.queryCkHtml(parmsMapForAssociation);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForAssociation) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=45&ckType=23&id=" + ckHtmlEntity.getId());

            String context = ckHtmlEntity.getHtml().substring(0, 350).replaceAll("</?[^>]+>", "").replaceAll("<a>\\s*|t|r|n</a>", "").replaceAll("&nbsp;", "");
            newsVo.setIntro((context.length() > 200 ? context.substring(0, 200) : context) + "... ");

            associationList.add(newsVo);
        }
        result.put("association", associationList);


        // 行业动态
        List<IndexNewsVo> insustryTrendList = new ArrayList<>();

        Map<String, Object> parmsMapForInsustryTrend = new HashMap<String, Object>();// 参数map
        parmsMapForInsustryTrend.put("ckType", 22);// 富文本类型 判断是哪个功能的富文本信息
        parmsMapForInsustryTrend.put("state", "1");
        //parmsMapForInsustryTrend.put("imgpd", "a"); // 不为空即可
        parmsMapForInsustryTrend.put("sort", "yes");
        parmsMapForInsustryTrend.put("index", 0);
        parmsMapForInsustryTrend.put("end", 8);
        List<CkHtmlEntity> ckHtmlEntityListForInsustryTrend = ckHtmlService.queryCkHtml(parmsMapForInsustryTrend);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityListForInsustryTrend) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=44&ckType=22&id=" + ckHtmlEntity.getId());
            insustryTrendList.add(newsVo);
        }
        result.put("insustryTrend", insustryTrendList);


        // 返回组装的信息
        indexResponseVo.setResult(result);
        System.out.println(indexResponseVo);
        return indexResponseVo;
    }


    /**
     * 顶部flash轮播图
     *
     * @param session
     * @return
     */
    @RequestMapping("topFlash")
    @ResponseBody
    public IndexFlashResponseVo topFlash(HttpSession session) {

        IndexFlashResponseVo indexFlashResponseVo = new IndexFlashResponseVo();
        List<IndexNewsVo> flashList = new ArrayList<>();


        Map<String, Object> parmsMap = new HashMap<String, Object>();// 参数map
        parmsMap.put("ckType", 5);// 富文本类型 判断是哪个功能的富文本信息
        parmsMap.put("state", "1");
        parmsMap.put("imgpd", "a"); // 不为空即可
        parmsMap.put("sort", "yes");
        List<CkHtmlEntity> ckHtmlEntityList = ckHtmlService.queryCkHtml(parmsMap);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityList) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=8&ckType=5&id=" + ckHtmlEntity.getId());
            newsVo.setImgsrc(pic_host + "/images/uploadimg/" + ckHtmlEntity.getImg());
            flashList.add(newsVo);
        }

        // 返回组装的信息
        indexFlashResponseVo.setResult(flashList);
        System.out.println(indexFlashResponseVo);
        return indexFlashResponseVo;
    }


    /**
     * 中部flash轮播图
     *
     * @param session
     * @return
     */
    @RequestMapping("middleFlash")
    @ResponseBody
    public IndexFlashResponseVo middleFlash(HttpSession session) {

        IndexFlashResponseVo indexFlashResponseVo = new IndexFlashResponseVo();
        List<IndexNewsVo> flashList = new ArrayList<>();

        Map<String, Object> parmsMap = new HashMap<String, Object>();// 参数map
        parmsMap.put("ckType", 6);// 富文本类型 判断是哪个功能的富文本信息
        parmsMap.put("state", "1");
        parmsMap.put("imgpd", "a"); // 不为空即可
        parmsMap.put("sort", "yes");
        List<CkHtmlEntity> ckHtmlEntityList = ckHtmlService.queryCkHtml(parmsMap);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityList) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=9&ckType=6&id=" + ckHtmlEntity.getId());
            newsVo.setImgsrc(pic_host + "/images/uploadimg/" + ckHtmlEntity.getImg());
            flashList.add(newsVo);
        }

        // 返回组装的信息
        indexFlashResponseVo.setResult(flashList);
        System.out.println(indexFlashResponseVo);
        return indexFlashResponseVo;
    }


    /**
     * 底部flash轮播图
     *
     * @param session
     * @return
     */
    @RequestMapping("bottomFlash")
    @ResponseBody
    public IndexFlashResponseVo bottomFlash(HttpSession session) {

        IndexFlashResponseVo indexFlashResponseVo = new IndexFlashResponseVo();
        List<IndexNewsVo> flashList = new ArrayList<>();

        Map<String, Object> parmsMap = new HashMap<String, Object>();// 参数map
        parmsMap.put("ckType", 7);// 富文本类型 判断是哪个功能的富文本信息
        parmsMap.put("state", "1");
        parmsMap.put("imgpd", "a"); // 不为空即可
        parmsMap.put("sort", "yes");
        List<CkHtmlEntity> ckHtmlEntityList = ckHtmlService.queryCkHtml(parmsMap);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityList) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?parent=7&menu=10&ckType=7&id=" + ckHtmlEntity.getId());
            newsVo.setImgsrc(pic_host + "/images/uploadimg/" + ckHtmlEntity.getImg());
            flashList.add(newsVo);
        }

        // 返回组装的信息
        indexFlashResponseVo.setResult(flashList);
        System.out.println(indexFlashResponseVo);
        return indexFlashResponseVo;
    }


    /**
     * 底部友情链接 (link表)
     *
     * @param session
     * @return
     */
    @RequestMapping("friendlyLink")
    @ResponseBody
    public IndexResponseVo friendlyLink(HttpSession session) {

        IndexResponseVo indexResponseVo = new IndexResponseVo();
        Map<String, List<IndexNewsVo>> result = new LinkedHashMap<>();

        // group1
        List<IndexNewsVo> group1List = new ArrayList<>();
        LinkEntity linkEntity1 = new LinkEntity();
        linkEntity1.setLinkType("1");
        List<LinkEntity> linkEntityList1 = linkService.queryLink(linkEntity1, 1, 50);

        for (LinkEntity le : linkEntityList1) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(le.getLinkName());
            newsVo.setLink(le.getLinkUrl());
            group1List.add(newsVo);
        }
        result.put("group1", group1List);

        // group2
        List<IndexNewsVo> group2List = new ArrayList<>();
        LinkEntity linkEntity2 = new LinkEntity();
        linkEntity2.setLinkType("2");
        List<LinkEntity> linkEntityList2 = linkService.queryLink(linkEntity2, 1, 50);

        for (LinkEntity le : linkEntityList2) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(le.getLinkName());
            newsVo.setLink(le.getLinkUrl());
            group2List.add(newsVo);
        }
        result.put("group2", group2List);

        // group3
        List<IndexNewsVo> group3List = new ArrayList<>();
        LinkEntity linkEntity3 = new LinkEntity();
        linkEntity3.setLinkType("3");
        List<LinkEntity> linkEntityList3 = linkService.queryLink(linkEntity3, 1, 50);

        for (LinkEntity le : linkEntityList3) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(le.getLinkName());
            newsVo.setLink(le.getLinkUrl());
            group3List.add(newsVo);
        }
        result.put("group3", group3List);

        // group4
        List<IndexNewsVo> group4List = new ArrayList<>();
        LinkEntity linkEntity4 = new LinkEntity();
        linkEntity4.setLinkType("4");
        List<LinkEntity> linkEntityList4 = linkService.queryLink(linkEntity4, 1, 50);

        for (LinkEntity le : linkEntityList4) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(le.getLinkName());
            newsVo.setLink(le.getLinkUrl());
            group4List.add(newsVo);
        }
        result.put("group4", group4List);

        // 返回组装的信息
        indexResponseVo.setResult(result);
        System.out.println(indexResponseVo);
        return indexResponseVo;
    }


    /**
     * 首页的搜索功能
     *
     * @param session
     * @param inputVal
     * @param curpage
     * @param size
     * @return
     */
    @RequestMapping("search")
    @ResponseBody
    public ListResponseVo search(HttpSession session, String inputVal, Integer curpage, Integer size) {

        List<IndexNewsVo> searchList = new ArrayList<>();

        Map<String, Object> parmsMap = new HashMap<String, Object>();// 参数map
        parmsMap.put("state", "1");
        parmsMap.put("sort", "yes");
        if (inputVal != null && !"".equals(inputVal.trim())) {
            parmsMap.put("inputVal", "%" + inputVal.trim() + "%");
        }

        if (curpage != 0 && size != 0) {
            int index = (curpage - 1) * size;
            int end = size;

            parmsMap.put("index", index);
            parmsMap.put("end", end);
        }

        List<CkHtmlEntity> ckHtmlEntityList = ckHtmlService.queryCkHtml(parmsMap);

        for (CkHtmlEntity ckHtmlEntity : ckHtmlEntityList) {
            IndexNewsVo newsVo = new IndexNewsVo();
            newsVo.setTitle(ckHtmlEntity.getTitle());
            newsVo.setLink(host + "/detail.jsp?id=" + ckHtmlEntity.getId());
            newsVo.setCreatedate(DateUtil.dateToStr(ckHtmlEntity.getCreateTime(), "yyyy-MM-dd"));
            searchList.add(newsVo);
        }

        int total = ckHtmlService.queryCkHtmlCount(parmsMap);

        // 返回组装的信息
        ListResponseVo listResponseVo = new ListResponseVo();
        listResponseVo.setResult(searchList);
        listResponseVo.setTotal(total);
        listResponseVo.setSize(size);
        listResponseVo.setCurpage(curpage);
        return listResponseVo;
    }


    /**
     * 首页注册功能
     *
     * @param session
     * @param userName
     * @param pwd
     * @param contactTel
     * @param companyName
     * @param province
     * @param city
     * @param area
     * @param companyAddress
     * @return
     */
    @RequestMapping("register")
    @ResponseBody
    public CommonResponseVo register(HttpSession session, String userName, String pwd, String contactTel, String companyName,
                                     String province, String city, String area, String companyAddress) {
        CommonResponseVo commonResponseVo = new CommonResponseVo();

        //String password = MD5.sign(pwd, pwd, "utf-8");
        companyName = companyName.replaceAll(" ", "");
        Map<String, Object> parmsMap = new HashMap<String, Object>();//参数map
        parmsMap.put("name", companyName);
        List<CompanyBaseInfo> list = companyBaseService.queryList(parmsMap);
        if (list.size() > 0) {
            commonResponseVo.setSuccess(false);
            commonResponseVo.setMsg("此企业信息已存在！");
            return commonResponseVo;
        }

        userName = userName.replaceAll(" ", "");
        Map<String, Object> parmsMap1 = new HashMap<String, Object>();//参数map
        parmsMap1.put("name", userName);
        List<UserEntity> list1 = userService.queryUserList(parmsMap1);
        if (list1 != null && list1.size() > 0) {
            commonResponseVo.setSuccess(false);
            commonResponseVo.setMsg("该用户名已存在！");
            return commonResponseVo;
        }

        // 注册信息
        UserEntity userEntity = new UserEntity();
        userEntity.setUserName(userName);
        userEntity.setUserPass(pwd);
        userEntity.setShowName(userName);
        userEntity.setIsDel("2");
        userEntity.setRoleId(4);
        userEntity.setRoleName("会员企业");

        // 企业基本信息
        CompanyBaseInfo companyBaseInfo = new CompanyBaseInfo();
        companyBaseInfo.setId(IdCreator.getId());
        companyBaseInfo.setName(companyName);
        companyBaseInfo.setContactTel(contactTel);
        companyBaseInfo.setProvince(province);
        companyBaseInfo.setCity(city);
        companyBaseInfo.setArea(area);
        companyBaseInfo.setAddress(companyAddress);
        companyBaseInfo.setCreateTime(new Date());

        try {
            userService.insertUser(userEntity);
            userEntity = userService.queryUserList(parmsMap1).get(0);

            companyBaseInfo.setUserId(userEntity.getId());
            companyBaseService.insert(companyBaseInfo);
        } catch (Exception e) {
            commonResponseVo.setSuccess(false);
            commonResponseVo.setMsg("系统异常，请联系管理员");
            return commonResponseVo;
        }

        commonResponseVo.setMsg("您已注册已成功，管理员审核通过后，即可登录！");
        return commonResponseVo;
    }


    /**
     * 首页的当前日期和星期
     *
     * @param session
     * @return
     */
    @RequestMapping("nowDate")
    @ResponseBody
    public CommonResponseVo nowDate(HttpSession session) {
        Date dt = new Date();
        String nowDate = "今天是" + DateUtil.convertDateToString("yyyy年MM月dd日", dt) + "    " + DateUtil.getWeek(dt);

        CommonResponseVo commonResponseVo = new CommonResponseVo();
        commonResponseVo.setResult(nowDate);
        return commonResponseVo;

    }


    /**
     * 安防资质查询
     *
     * @param model
     * @param nameOrNum
     * @return
     */
    @RequestMapping("/queryAnFangZiZhi")
    @ResponseBody
    public ComponseSearchResponseVo queryCompanyZhengShu(Model model, String nameOrNum) {
        ComponseSearchResponseVo componseSearchResponseVo = new ComponseSearchResponseVo();

        if (StringUtil.isBlank(nameOrNum)) {
            componseSearchResponseVo.setSuccess(false);
            componseSearchResponseVo.setMsg("请输入搜索信息");
            return componseSearchResponseVo;
        }

        CertificatoryComp cc;

        try {
            List<CertificatoryComp> ccList = certificatoryCampanyService.selectByTypeAndNameOrNum("安防工程企业设计施工维护资质证书", nameOrNum);
            if (ccList == null || ccList.isEmpty()) {
                componseSearchResponseVo.setSuccess(false);
                componseSearchResponseVo.setMsg("没有找到相关的证书信息！");
                return componseSearchResponseVo;
            }
            cc = ccList.get(0);
        } catch (Exception var7) {
            componseSearchResponseVo.setSuccess(false);
            componseSearchResponseVo.setMsg("系统异常，请联系管理员！");
            return componseSearchResponseVo;
        }

        componseSearchResponseVo.setZhengShuType(cc.getCertificateType());
        componseSearchResponseVo.setDanWeiMingCheng(cc.getCompanyName());
        componseSearchResponseVo.setDengJi(cc.getCertificateLevel());
        componseSearchResponseVo.setZhengShuCode(cc.getCertificateNum());
        componseSearchResponseVo.setZhengShuYouXiaoQi(DateUtil.convertDateToString("yyyy-MM-dd", cc.getCertificateValidity()));

        return componseSearchResponseVo;

    }

    /**
     * 信用等级查询
     *
     * @param model
     * @param nameOrNum
     * @return
     */
    @RequestMapping("/queryXinYongDengJi")
    @ResponseBody
    public ComponseSearchResponseVo queryXinYongDengJi(Model model, String nameOrNum) {
        ComponseSearchResponseVo componseSearchResponseVo = new ComponseSearchResponseVo();

        if (StringUtil.isBlank(nameOrNum)) {
            componseSearchResponseVo.setSuccess(false);
            componseSearchResponseVo.setMsg("请输入搜索信息");
            return componseSearchResponseVo;
        }

        CertificatoryComp cc;

        try {
            List<CertificatoryComp> ccList = certificatoryCampanyService.selectByTypeAndNameOrNum("安防行业企业信用等级证书", nameOrNum);
            if (ccList == null || ccList.isEmpty()) {
                componseSearchResponseVo.setSuccess(false);
                componseSearchResponseVo.setMsg("没有找到相关的信用等级信息！");
                return componseSearchResponseVo;
            }
            cc = ccList.get(0);
        } catch (Exception var7) {
            componseSearchResponseVo.setSuccess(false);
            componseSearchResponseVo.setMsg("系统异常，请联系管理员！");
            return componseSearchResponseVo;
        }

        componseSearchResponseVo.setCreditZhengShuType(cc.getCertificateType());
        componseSearchResponseVo.setCreditDanWeiMingCheng(cc.getCompanyName());
        componseSearchResponseVo.setCreditDengJi(cc.getCertificateLevel());
        componseSearchResponseVo.setCreditZhengShuCode(cc.getCertificateNum());
        componseSearchResponseVo.setCreditZhengShuYouXiaoQi(DateUtil.convertDateToString("yyyy-MM-dd", cc.getCertificateValidity()));

        return componseSearchResponseVo;

    }


    /**
     * 人员查询
     *
     * @param model
     * @param nameOrNum
     * @return
     */
    @RequestMapping("/queryRenYuan")
    @ResponseBody
    public ComponseSearchResponseVo queryRenYuan(Model model, String nameOrNum) {
        ComponseSearchResponseVo componseSearchResponseVo = new ComponseSearchResponseVo();

        if (StringUtil.isBlank(nameOrNum)) {
            componseSearchResponseVo.setSuccess(false);
            componseSearchResponseVo.setMsg("请输入搜索信息");
            return componseSearchResponseVo;
        }

        CertificatoryPer cc;

        try {
            List<CertificatoryPer> ccList = certificatoryPerService.selectByNameOrNum(nameOrNum);
            if (ccList == null || ccList.isEmpty()) {
                componseSearchResponseVo.setSuccess(false);
                componseSearchResponseVo.setMsg("没有找到相关的人员信息！");
                return componseSearchResponseVo;
            }
            String userId = ccList.get(0).getBelCompany();

            Employee employee = employeeService.selectByPrimaryKey(Integer.parseInt(userId));
            cc = ccList.get(0);
            Map<String, Object> parmsMap = new HashMap<String, Object>();//参数map
            if (null != employee && null != employee.getCompanyId()) {
                parmsMap.put("userId", employee.getCompanyId());
                UserEntity userEntity = userService.queryUser(parmsMap);

                cc.setBelCompany(userEntity.getUserName());
            }

        } catch (Exception var7) {
            componseSearchResponseVo.setSuccess(false);
            componseSearchResponseVo.setMsg("系统异常，请联系管理员！");
            return componseSearchResponseVo;
        }

        componseSearchResponseVo.setPersonName(cc.getPerName());
        componseSearchResponseVo.setPersonAuditStatus(cc.getAuditStatus());
        componseSearchResponseVo.setPersonZhengShuCode(cc.getCertificateNum());
        componseSearchResponseVo.setPersonCompanty(cc.getBelCompany());

        return componseSearchResponseVo;

    }


}
